package com.twu.biblioteca.Models;

import java.util.ArrayList;
import java.util.List;

public class BooksManager {

    private List<Book> booksList;

    public BooksManager() {
        booksList = new ArrayList<Book>();
        Book tmp = new Book(1, "Harry Potter", "J.K Rowling");
        booksList.add(tmp);
        tmp = new Book(2, "AAA", "BBB");
        booksList.add(tmp);
        tmp = new Book(3, "ZZZ", "SSS");
        booksList.add(tmp);
        tmp = new Book(4, "XXX", "DDD");
        booksList.add(tmp);
        tmp = new Book(5, "CCC", "FFF");
        booksList.add(tmp);
        tmp = new Book(6, "VVV", "GGG");
        booksList.add(tmp);
    }

    public List<Book> getBooksList() {
        return booksList;
    }

    public String showBooks() {
        String books = "\nID - Title - Author \n";
        for (Book book: getBooksList()) {
            books += book.getBookID() + "\t" + book.getTitle() + "\t" + book.getAuthor() + "\n";
        }
        return books;
    }

    public boolean reserveBook(int bookID) {
        for (Book book: getBooksList()) {
            if(book.getBookID() == bookID) {
                book.setReserved();
                return true;
            }
        }
        return false;
    }
}
